/**
 * Copyright (c) 2011-2014, junchen (homeanter@163.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package xin.tianhui.cloud.weblog.web;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;
import xin.tianhui.cloud.weblog.core.model.dto.PagingDTO;
import xin.tianhui.cloud.weblog.core.model.dto.PagingWrapper;
import xin.tianhui.cloud.weblog.core.model.vo.PagingVO;
import xin.tianhui.cloud.weblog.core.model.vo.ResponseBody;
import xin.tianhui.cloud.weblog.manager.IArticleMng;
import xin.tianhui.cloud.weblog.model.dto.ArticleAlterDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleQueryDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleResultDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleTypeResultDTO;

/**
 * @author junchen homeanter@163.com
 * @Data 2018-04-16 21:31:37
 */
@Slf4j
@RestController
@RequestMapping("article")
public class ArticleController {
	
	@Autowired
	private IArticleMng articleMng;
	
	@PostMapping("page")
	public PagingVO<ArticleResultDTO> paging(@RequestBody PagingWrapper<ArticleQueryDTO> wrapper){
		PagingDTO paging = wrapper.getPaging();
		return articleMng.articlePaging(paging, wrapper.getParam());
	}
	
	@GetMapping("type")
	public List<ArticleTypeResultDTO> articleType() {
		return articleMng.articleType();
	}
	
	@GetMapping("{id}")
	public ArticleResultDTO article(@PathVariable("id")Integer id) {
		return articleMng.getArticle(id);
	}
	
	
	@PostMapping("alter")
	public ResponseEntity<Object> alterArticle(@RequestBody ArticleAlterDTO articleAlter,HttpServletRequest request) {
		ArticleResultDTO resultDto = articleMng.alterArticle(articleAlter);
		return ResponseEntity.ok(new ResponseBody());
	}
}
